package com.han.fu.api.business.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.han.fu.api.business.model.ao.ActivityAddAo;
import com.han.fu.api.business.model.ao.ActivityDeleteAo;
import com.han.fu.api.business.model.ao.ActivityPageAo;
import com.han.fu.api.business.model.ao.ActivityUpdateAo;
import com.han.fu.api.business.model.vo.ActivityInfoVo;
import com.han.fu.api.business.model.vo.ActivityVo;
import com.han.fu.api.business.service.IActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * 活动接口
 *
 * @author: star
 * @date: 2021-08-05
 */
@RestController
public class ActivityController {

    @Autowired
    IActivityService iActivityService;

    /**
     * 活动分页查询
     *
     * @param ao 分页查询条件
     * @return Page<ActivityVo> 分页数据
     */
    @PreAuthorize("hasRole('tourist') OR hasRole('member') OR hasRole('admin')")
    @PostMapping("/activity/page")
    public Page<ActivityVo> queryActivityPage(@Validated @RequestBody ActivityPageAo ao) {
        return iActivityService.queryActivityPage(ao);
    }

    /**
     * 活动明细查询
     *
     * @param id 主键
     * @return ActivityInfoVo 明细
     */
    @PreAuthorize("hasRole('tourist') OR hasRole('member') OR hasRole('admin')")
    @GetMapping("/activity/detail")
    public ActivityInfoVo queryActivityDetail(@NotNull(message = "ID不能为空") @RequestParam String id) {
        return iActivityService.queryActivityDetail(id);
    }

    /**
     * 活动新增数据
     *
     * @param ao 数据
     */
    @PreAuthorize("hasRole('tourist') OR hasRole('member') OR hasRole('admin')")
    @PostMapping("/activity/add")
    public void addActivity(@Validated @RequestBody ActivityAddAo ao) {
        iActivityService.addActivity(ao);
    }

    /**
     * 活动修改数据
     *
     * @param ao 数据
     */
    @PreAuthorize("hasRole('tourist') OR hasRole('member') OR hasRole('admin')")
    @PostMapping("/activity/update")
    public void updateActivity(@Validated @RequestBody ActivityUpdateAo ao) {
        iActivityService.updateActivity(ao);
    }

    /**
     * 活动删除数据
     *
     * @param ao 数据
     */
    @PreAuthorize("hasRole('tourist') OR hasRole('member') OR hasRole('admin')")
    @PostMapping("/activity/delete")
    public void deleteActivity(@Validated @RequestBody ActivityDeleteAo ao) {
        iActivityService.deleteActivity(ao);
    }

}